package com.hclc.entity.model.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

/** ('-')
 * 排序方式
 * @author ljj
 * @version 1.0
 * @date 2020/10/18 20:04
 */
public enum SortEnum implements IEnum<Integer> {
    /**
     * 正序
     * */
    ASC(1, "正序"),


    /**
     * 倒序
     * */
    DESC(2, "倒序"),

    /**
     * 不排序
     * */
    NO(0,"不排序");


    @JsonValue
    @EnumValue
    private final int code;


    private final String desc;

    SortEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    @Override
    public Integer getValue() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public static SortEnum find(String desc) throws IllegalArgumentException {
        for (SortEnum model : SortEnum.values()) {
            if (model.getDesc().equals(desc)) {
                return model;
            }
        }
        throw new IllegalArgumentException();
    }

    @JsonCreator
    public static SortEnum find(int code) throws IllegalArgumentException {
        for (SortEnum model : SortEnum.values()) {
            if (model.getValue() == code) {
                return model;
            }
        }
        throw new IllegalArgumentException();
    }
}
